import request from '@/utils/request'
import { getToken } from '@/utils/auth'

export default{
    //查看所有证书列表
    getCertificateList(page_num,page_size){
        return request({
          url:`/certificate/list?page_num=${page_num}&page_size=${page_size}`,
          method: 'GET',
          headers: {
            'Authorization':getToken()
          }
        })
    },
    
    //根据id查找证书
    getCertificateById(certificate_id){
        return request({
            url:`certificate?certificate_id=${certificate_id}`,
            method:'GET',
            headers: {
                'Authorization':getToken()
            }
        })
    },

    //添加/编辑证书
    addOrEditCertificate(certificate_form){
        if(certificate_form.certificate_id){
            return request({
                url:`/certificate`,
                method:'PUT',
                data:certificate_form, 
                headers: {
                    'Authorization':getToken()
                }});
          }
          else{
            return request({
                url:`/certificate`,
                method:'POST',
                data:certificate_form, 
                headers: {
                    'Authorization':getToken()
                }});
          }
        
    },

    //删除证书
    delCertificate(certificate_id){
        return request({
            url:`/certificate?certificate_id=${certificate_id}`,
            method:'DELETE',
            headers:{
                'Authorization':getToken()
            }
        })
    },
    
    //证书选择框----获取所有用户
    getUserList(page_num,page_size){
        return request({
            url:`/user/list?page_num=${page_num}&page_size=${page_size}`,
            method:'GET',
            headers:{
                'Authorization':getToken()
            }
        })
    },

    //根据所选用户渲染该证书列表
    getCertificateByUser(page_num,page_size,user_id){
        return request({
            url:`/certificate/userCerList?pageNum=${page_num}&pageSize=${page_size}&useId=${user_id}`,
            method:'GET',
            headers:{
                'Authorization':getToken()
            }
        })
    },

    //给用户添加证书
    addCertificateToUser(certificate_id,user_id){
        return request({
            url:`/certificate/user?certificate_id=${certificate_id}&user_id=${user_id}`,
            method:'POST',
            headers:{
                'Authorization':getToken()
            }
        })
    },

    //删除用户所有的证书
    delUserAllCertificate(user_id){
        return request({
            url:`/certificate/user?user_id=${user_id}`,
            method:'DELETE',
            headers:{
                'Authorization':getToken()
            }
        })
    },

    //删除用户的某个证书
    delUserCertificate(cer_id,user_id){
        return request({
            url:`certificate/delUserCer?cerId=${cer_id}&userId=${user_id}`,
            method:'DELETE',
            headers:{
                'Authorization':getToken()
            }
        })
    },

    //导入证书列表
    importCetData(){
        return request({
            url:`/certificate/user/batchAdd`,
            method:'POST',
            headers:{
                'Authorization':getToken()
            },
           
        })
    },

    //导出证书列表
    exportCerData(){
        return request({
            url:`/certificate/user/exportData`,
            method:'GET',
            headers:{
                'Authorization':getToken()
            },
            responseType: "blob"
        })
    },

    //打印证书PDF
    getCerPdf(cer_id,user_id){
        return request({
            url:`/certificate/user/getPDf?cerId=${cer_id}&userId=${user_id}`,
            method:'GET',
            headers:{
                'Authorization':getToken()
            },
            responseType: "blob"
        })
    }

    //根据所选用户渲染该证书数据列表
    // getCertificateDataByUser(user_id){
    //     return request({
    //         url:`/certificate/user/data?user_id=${user_id}`,
    //         method:'GET',
    //         headers:{
    //             'Authorization':getToken()
    //         }
    //     })
    // },

    //给用户添加/更新证书数据
    // addOrUpdateCertificateData(certificateData_form){
    //     if(certificateData_form.user_id){
    //         return request({
    //             url:`/certificate/user/data`,
    //             method:'PUT',
    //             data:certificateData_form, 
    //             headers: {
    //                 'Authorization':getToken()
    //             }});
    //       }
    //       else{
    //         return request({
    //             url:`/certificate/user/data`,
    //             method:'POST',
    //             data:certificateData_form, 
    //             headers: {
    //                 'Authorization':getToken()
    //             }});
    //       }
    // },

    //删除用户数据
    // delCertificateData(user_id){
    //     return request({
    //         url:`/certificate/user/data?userCertificate_id=${user_id}`,
    //         method:'DELETE',
    //         headers:{
    //             'Authorization':getToken()
    //         }
    //     })
    // },

    
}